#include "EffectManager.h"

EffectManager::EffectManager()
{
	isDone = false;
	spriteId = -1;

}

EffectManager* EffectManager::_singleton = NULL;
int EffectManager::currentBridgeIndex = -1;
vector<EffectEntity*>* EffectManager::_effects= new vector<EffectEntity*>();

void EffectManager::initialize()
{
	if(_singleton == NULL)
	{
		_singleton = new EffectManager();
	}
}

EffectManager* EffectManager::getInstatnse()
{
	initialize();
	return _singleton;
}

void EffectManager::createEffect(int effectType, double x, double y)
{
	_effects->push_back(new EffectEntity(EffectDataFactory::getEffect(effectType), x, y));
}

void EffectManager::uppdate(long time)
{

	int size = _effects->size();
	if(size > 0)
	{
		std::vector<EffectEntity*>::iterator it = _effects->begin();
		for(;it != _effects->end();)
		{
			if((*it)->isDone)
			{
				it = _effects->erase(it);
			}
			else
			{
				(*it)->update(time);
				++it;
			}
		}
	}
}

void EffectManager::draw(long time)
{
	int size = _effects->size();
	if(size > 0)
	{
		std::vector<EffectEntity*>::iterator it = _effects->begin();
		for(; it != _effects->end(); it++)
		{
			(*it)->draw(time);
		}
	}
}

void EffectManager::_initSprites(int SpriteId, int framerate)
{
	sprite = new Sprite(*(GameDeviceSingleton::getInstance()->getSpriteHandler()), SpriteId, false, framerate);
}